﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using BrewXML.Core.Data;
using BrewXML.Core.Services.NavigationServices;
using Cirrious.CrossCore;
using Cirrious.MvvmCross.ViewModels;

namespace BrewXML.Core.ViewModels
{
    public class RecipeDetailPageViewModel :BaseViewModel
    {
        
         #region Properties

        #region AllowAdd

        private bool mAllowAdd = false;
        public bool AllowAdd
        {
            get
            {
                return mAllowAdd;
            }
            set
            {
                mAllowAdd = value;
                RaisePropertyChanged("AllowAdd");
            }
        }
        #endregion
   
      

        #region RECIPES

        private RECIPE mRecipe;

        public RECIPE RECIPE
        {
            get
            {
                return mRecipe;
            }
            set
            {
                mRecipe = value;
                RaisePropertyChanged("RECIPE");
                //if (RECIPE != null) RefreshRecipe();
            }
        }
        #endregion

        #region ListStyle
        private List<STYLE> mLisStyle=new List<STYLE>();
        public List<STYLE> ListStyle
        {
            get
            {
                return mLisStyle;
            }
            set
            {
                mLisStyle = value;
                RaisePropertyChanged("ListStyle");
            }
        }
        #endregion

        #region Style

        private STYLE mStyle;

        public STYLE Style
        {
            get
            {
                return mStyle;
            }
            set
            {
                mStyle = value;
                RaisePropertyChanged("Style");
            }
        }
        #endregion

        #region ListGrainPicked
        private List<GRAIN> mListGrainPicked = new List<GRAIN>();
        public List<GRAIN> ListGrainPicked
        {
            get
            {
                return mListGrainPicked;
            }
            set
            {
                mListGrainPicked = value;
                RaisePropertyChanged("ListGrainPicked");
            }
        }
        #endregion

        #region Grain

        private GRAIN mGrain;
        public GRAIN Grain
        {
            get
            {
                return mGrain;
            }
            set
            {
                mGrain = value;
                RaisePropertyChanged("Grain");
            }
        }
        #endregion

        

        #region ListHopPicked
        private List<HOP> mListHopPicked = new List<HOP>();
        public List<HOP> ListHopPicked
        {
            get
            {
                return mListHopPicked;
            }
            set
            {
                mListHopPicked = value;
                RaisePropertyChanged("ListHopPicked");
            }
        }
        #endregion

        #region HOP

        private HOP mHop;
        public HOP Hop
        {
            get
            {
                return mHop;
            }
            set
            {
                mHop = value;
                RaisePropertyChanged("Hop");
            }
        }
        #endregion

       

        #region ListMiscPicked
        private List<MISC> mListMiscPicked = new List<MISC>();
        public List<MISC> ListMiscPicked
        {
            get
            {
                return mListMiscPicked;
            }
            set
            {
                mListMiscPicked = value;
                RaisePropertyChanged("ListMiscPicked");
            }
        }
        #endregion

        #region MISC

        private MISC mMisc;
        public MISC Misc
        {
            get
            {
                return mMisc;
            }
            set
            {
                mMisc = value;
                RaisePropertyChanged("Misc");
            }
        }
        #endregion
         #endregion

        #region Command

        #region Navigate
        private MvxCommand<string> mNavigateCommand;

        public MvxCommand<string> NavigateCommand
        {
            get
            {
                return new MvxCommand<string>(NavigatePage);
            }
        }

        private void NavigatePage( string parameter)
        {
            switch (parameter)
            {
                case "ManagerDataPage":
                    Mvx.Resolve<INavigationService>().NavigateTo(PageNames.ManagerDataPage); break;
                case "HopsPage":
                    Mvx.Resolve<INavigationService>().NavigateTo(PageNames.HopsPage); break;
                case "GrainsPage":
                    Mvx.Resolve<INavigationService>().NavigateTo(PageNames.GrainsPage); break;
                case "MiscsPage":
                    Mvx.Resolve<INavigationService>().NavigateTo(PageNames.MiscsPage); break;
                case "StylesPage":
                    Mvx.Resolve<INavigationService>().NavigateTo(PageNames.StylesPage); break;
            }
           
        }
        #endregion

        #region Navigate
        private MvxCommand<object> mNavigateDetailCommand;

        public MvxCommand<object> NavigateDetailCommand
        {
            get
            {
                return new MvxCommand<object>(NavigateDetailPage);
            }
        }

        private void NavigateDetailPage(object parameter)
        {

            if (parameter is HOP)
            {
                Mvx.Resolve<HopDetailPageViewModel>().Hop = parameter as HOP;
                Mvx.Resolve<HopDetailPageViewModel>().EnableAppbar = false;
                Mvx.Resolve<INavigationService>().NavigateTo(PageNames.HopDetailPage);
            }
            if (parameter is GRAIN)
            {
                Mvx.Resolve<GrainDetailPageViewModel>().Grain = parameter as GRAIN;
                Mvx.Resolve<GrainDetailPageViewModel>().EnableAppbar = false;
                Mvx.Resolve<INavigationService>().NavigateTo(PageNames.GrainDetailPage);
            }
            if (parameter is MISC)
            {
                Mvx.Resolve<MiscDetailPageViewModel>().Misc = parameter as MISC;
                Mvx.Resolve<MiscDetailPageViewModel>().EnableAppbar = false;
                Mvx.Resolve<INavigationService>().NavigateTo(PageNames.MiscDetailPage);
            }
            if (parameter is STYLE)
            {
                Mvx.Resolve<StyleDetailPageViewModel>().Style = parameter as STYLE;
                Mvx.Resolve<StyleDetailPageViewModel>().EnableAppbar = false;
                Mvx.Resolve<INavigationService>().NavigateTo(PageNames.StyleDetailPage);
            }
                
        }
        #endregion

        #region AddItem
        private MvxCommand<string> mAddCommand;

        public MvxCommand<string> AddCommand
        {
            get
            {
                return new MvxCommand<string>(AddItem);
            }
        }

        private void AddItem(string parameter)
        {
            switch (parameter)
            {
                case "Grain":
                {                   
                    RECIPE.GRAINS.Add(Grain);
                    var ttt = RECIPE;
                    RECIPE = null;
                    RECIPE = ttt;
                    break;
                }
                   
                case "Hop":
                {
                    RECIPE.HOPS.Add(Hop);
                    var ttt = RECIPE;
                    RECIPE = null;
                    RECIPE = ttt; 
                    break;
                }
                    
                case "Misc":
                {
                    RECIPE.MISCS.Add(Misc);
                    var ttt = RECIPE;
                    RECIPE = null;
                    RECIPE = ttt;
                    break;
                }
               
            }

        }
        #endregion



        #region DeleteItem
        private MvxCommand<object> mDeleteCommand;

        public MvxCommand<object> DeleteCommand
        {
            get
            {
                return new MvxCommand<object>(DeleteItem);
            }
        }

        private void DeleteItem(object parameter)
        {
            if(parameter is GRAIN)
            {

                    RECIPE.GRAINS.Remove(parameter as GRAIN);
                    var ttt = RECIPE;
                    RECIPE = null;
                    RECIPE = ttt;
            }
            if (parameter is HOP)
            {

                RECIPE.HOPS.Remove(parameter as HOP);
                var ttt = RECIPE;
                RECIPE = null;
                RECIPE = ttt;

            }
            if (parameter is MISC)
            {

                RECIPE.MISCS.Remove(parameter as MISC);
                var ttt = RECIPE;
                RECIPE = null;
                RECIPE = ttt;

            }
                   


        }
        #endregion
        #endregion

        #region Function

        public void RefreshRecipe()
        {
            var ttt = RECIPE;
            RECIPE = null;
            RECIPE = ttt;
        }
        #endregion

        #region Initialize

        public void Initialize()
        {

        }
        #endregion

        #region Constructors

        public RecipeDetailPageViewModel()
        {
            Initialize();
        }
        #endregion
    }
}
